var events = require('events');
var eventEmitter = new events.EventEmitter();

var listener1 = function(){
	console.log('listener1');
}
var listener2 = function(){
	console.log('listener2');
}

//利用addListener可以添加多个监听事件
eventEmitter.on('connection',listener1);
eventEmitter.addListener('connection',listener2);

//listenerCount(events,eventName)返回eventName绑定的监听事件的个数
var counts = events.EventEmitter.listenerCount(eventEmitter,'connection');

console.log(counts+' 个监听器事件');

//emit(eventName)用于触发事件eventName
eventEmitter.emit('connection');

//removeListener(eventName,eventHandler)用于从事件eventName上移除事件eventHandler
eventEmitter.removeListener('connection',listener1);

console.log('listener1不再绑定');

eventEmitter.emit('connection');

var counts2 = events.EventEmitter.listenerCount(eventEmitter,'connection');
console.log(counts2+' 个监听事件');

console.log('程序执行完毕');
